package br.com.sgdc.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import br.com.sgdc.Facade;
import br.com.sgdc.view.action.ActionConfirmarButtonWindowEsqueceuSenha;
import br.com.sgdc.view.util.Imagens;

public class WindowEsqueceuSenha {
	public JDialog window = new JDialog();
	public JLabel perguntaLabel = new JLabel();
	public JTextField respostaTextField = new JTextField();
	public JButton confirmarButton = new JButton("Confirmar");

	private Facade facade = new Facade();

	public WindowEsqueceuSenha() {
		window.setTitle(".:: SGDC - Esqueceu a Senha ::.");
		window.setLayout(new BorderLayout());
		window.setSize(370, 150);
		window.setLocationRelativeTo(null);
		window.setIconImage(new ImageIcon(getClass().getResource(Imagens.cloud)).getImage());
	}

	public void initComponentesJanela() {
		this.initComponentes();

		window.setLayout(new BorderLayout());
		window.add(BorderLayout.EAST,new JPanel());
		window.add(BorderLayout.WEST,new JPanel());
		window.add(BorderLayout.CENTER,constructPrincipalPanel());
		window.add(BorderLayout.NORTH,new JPanel());
		window.add(BorderLayout.SOUTH,new JPanel());
		window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		window.setVisible(true);
	}

	private void initComponentes() {
		try {
			this.contructAction();
			String pergunta = facade.getConfiguracaoSistemaDao().listaConfiguracaoSistema().getPergunta();
			perguntaLabel.setText(pergunta);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private Component constructPrincipalPanel() {
		JPanel panelGrid = new JPanel();
		panelGrid.setLayout(new GridLayout(4,1));
		panelGrid.add(perguntaLabel);
		panelGrid.add(respostaTextField);
		panelGrid.add(new JPanel());
		panelGrid.add(confirmarButton);
		
		JPanel panelFlow = new JPanel();
		panelFlow.setLayout(new FlowLayout(FlowLayout.CENTER));
		panelFlow.add(panelGrid);
		
		return panelFlow;
	}

	private void contructAction() {
		confirmarButton.addActionListener(new ActionConfirmarButtonWindowEsqueceuSenha(this));
	}
}
